package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.shopping.domain.Bbs;
import com.ruoyi.shopping.service.IBbsService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户端留言Controller
 *
 * @author scx
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/shopping/bbsUser")
public class BbsUserController extends BaseController
{
    @Autowired
    private IBbsService bbsService;

    /**
     * 查询用户端留言列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:list')")
    @GetMapping("/list")
    public TableDataInfo list(Bbs bbs)
    {
        startPage();
        bbs.setBelongs(DicConstants.BUSINESS_Customer.getCode());
        List<Bbs> list = bbsService.selectBbsList(bbs);
        return getDataTable(list);
    }

    /**
     * 导出用户端留言列表
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:export')")
    @Log(title = "用户端留言", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Bbs bbs)
    {
        List<Bbs> list = bbsService.selectBbsList(bbs);
        ExcelUtil<Bbs> util = new ExcelUtil<Bbs>(Bbs.class);
        return util.exportExcel(list, "用户端留言数据");
    }

    /**
     * 获取用户端留言详细信息
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bbsService.selectBbsById(id));
    }

    /**
     * 新增用户端留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:add')")
    @Log(title = "用户端留言", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Bbs bbs)
    {
        return toAjax(bbsService.insertBbs(bbs));
    }

    /**
     * 修改用户端留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:edit')")
    @Log(title = "用户端留言", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Bbs bbs)
    {
        bbs.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(bbsService.updateBbs(bbs));
    }

    /**
     * 删除用户端留言
     */
    @PreAuthorize("@ss.hasPermi('shopping:bbsUser:remove')")
    @Log(title = "用户端留言", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bbsService.logicDeleteBbs(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
